package com.douban.business;

import java.util.Collection;

import junit.framework.TestCase;

import com.douban.constants.DoubanMediaTypeConstant;
import com.douban.constants.DoubanUserActionConstant;

public class DoubanUserRequestTest extends TestCase {

	public void testSubStract() throws Exception{
		DoubanMediaTypeConstant c = DoubanMediaTypeConstant.BOOK;
		DoubanUserActionConstant d = DoubanUserActionConstant.COLLECT;
		Collection cc = DoubanMediaTypeConstant.getAllConstants(DoubanMediaTypeConstant.class);
		Object[] objs = (cc.toArray(new DoubanMediaTypeConstant[cc.size()]));
		DoubanMediaTypeConstant[] arrayt = (DoubanMediaTypeConstant[])objs;

		
		DoubanUserRequest ur1 = new DoubanUserRequest("username", 
				arrayt, 
				(DoubanUserActionConstant[])(DoubanUserActionConstant.getAllConstants(DoubanUserActionConstant.class).toArray(new DoubanUserActionConstant[DoubanUserActionConstant.getAllConstants(DoubanUserActionConstant.class).size()])));
		
		DoubanUserRequest ur4 = new DoubanUserRequest("username", 
				new DoubanMediaTypeConstant[]{},new DoubanUserActionConstant[]{DoubanUserActionConstant.COLLECT});
		
		DoubanUserRequest ur3 = new DoubanUserRequest("username", 
				new DoubanMediaTypeConstant[]{DoubanMediaTypeConstant.BOOK},new DoubanUserActionConstant[]{});
		
		DoubanUserRequest ur2 = new DoubanUserRequest("username", 
				new DoubanMediaTypeConstant[]{},new DoubanUserActionConstant[]{});
		

		

		
		ur1.substractRequest(ur4);
		assertEquals(3, ur1.getMediaTypes().length);
		assertEquals(false, ur1.areRequestsAcomplished());
		assertEquals(6, ur1.getRequests().size());
		
		ur1.substractRequest(ur3);
		assertEquals(2, ur1.getMediaTypes().length);
		assertEquals(false, ur1.areRequestsAcomplished());
		assertEquals(4, ur1.getRequests().size());
		
		ur4.substractRequest(ur1);
		assertEquals(3, ur4.getMediaTypes().length);
		assertEquals(false, ur4.areRequestsAcomplished());
		assertEquals(3, ur4.getRequests().size());
		
		ur1.substractRequest(ur2);
		assertEquals(0, ur1.getMediaTypes().length);
		assertEquals(true, ur1.areRequestsAcomplished());
		assertEquals(0, ur1.getRequests().size());
		
	}
}
